package com.yunda.nebula.gateway.sync.nacos;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.config.listener.AbstractSharedListener;
import com.yunda.nebula.gateway.core.DataChangedListener;
import com.yunda.nebula.gateway.core.entity.ConfigData;
import com.yunda.nebula.gateway.core.enums.DataEventTypeEnum;

/**
 * @author zhiguo.dong
 * @date 2020/9/23
 */
public class AppInfoRefreshListener extends AbstractSharedListener {
    private NacosSyncDataService nacosSyncDataService;


    public AppInfoRefreshListener(NacosSyncDataService nacosSyncDataService) {
        this.nacosSyncDataService = nacosSyncDataService;
    }

    @Override
    public void innerReceive(String dataId, String group, String configInfo) {
        ConfigData configData = JSONObject.parseObject(configInfo, ConfigData.class);
        DataChangedListener dataChangedListener = nacosSyncDataService.getDataChangedListener();
        dataChangedListener.onAppChanged(configData, DataEventTypeEnum.UPDATE);
    }
}
